/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package modules.estoque.util;


import java.io.File;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * Hibernate Utility class with a convenient method to get Session Factory object.
 *
 * @author Clezio
 */
public class HibernateUtil {
    private static final SessionFactory sessionFactory;
    private static Configuration cfg;
    static {
        try {
            // Create the SessionFactory from standard (hibernate.cfg.xml) 
            // config file.
            setCfg(new AnnotationConfiguration().configure("hibernate.cfg.xml"));
            sessionFactory = getCfg().buildSessionFactory();
        } catch (Throwable ex) {
            // Log the exception. 
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    /**
     * @return the cfg
     */
    public static Configuration getCfg() {
        return cfg;
    }

    /**
     * @param aCfg the cfg to set
     */
    public static void setCfg(Configuration aCfg) {
        cfg = aCfg;
    }
}
